package com.smart.parking.controller.backstage;

import java.util.Arrays;
import java.util.Map;

import com.smart.parking.config.Result;
import com.smart.parking.entity.VehicleEntity;
import com.smart.parking.param.AliPay;
import com.smart.parking.service.VehicleService;
import com.smart.parking.utils.PageUtils;
import com.smart.parking.vo.VehicleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 车辆信息表
 *
 * @author ciyun
 * @email ciyun@gmail.com
 * @date 2022-10-30 14:12:10
 */
@RestController
@RequestMapping("/vehicle")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(@RequestParam Map<String, Object> params) {
        PageUtils page = vehicleService.queryPage(params);

        return Result.ok().put("page", page);
    }

    /**
     * 增加车辆
     *
     * @param vehicleVO 车辆信息
     * @return {@link Result}
     */
    @PostMapping("/addVehicle")
    public Result addVehicle(@RequestBody VehicleVO vehicleVO) {
        boolean flag = vehicleService.addVehicle(vehicleVO);
        if (flag) {
            return Result.ok("新增成功!");
        }
        return Result.error("新增失败!");
    }

    /**
     * 结束停车
     *
     * @param vehicleVO 车辆信息
     * @return {@link Result}
     */
    @PostMapping("/endVehicle")
    public Result endVehicle(@RequestBody VehicleVO vehicleVO) {
        AliPay aliPay = vehicleService.endVehicle(vehicleVO);
        return Result.ok().put("aliPay", aliPay);
    }

    /**
     * 手动释放车位
     */
    @DeleteMapping("/manualRelease")
    public Result manualRelease(@RequestParam("vehicleId") Long vehicleId){
        vehicleService.manualRelease(vehicleId);
        return Result.ok();
    }


    /**
     * 批量手动释放
     *
     * @return {@link Result}
     */
    @DeleteMapping("/manualReleases")
    public Result manualReleases(@RequestBody Long[] vehicleIds){
        vehicleService.manualReleases(vehicleIds);
        return Result.ok();
    }

}
